///*
// * AssignmentAlgorithmTester.java
// * JUnit based test
// *
// * Created on 1. Dezember 2007, 14:48
// *
// * This file is part of the TimeFinder project.
// * Visit http://www.timefinder.de for more information.
// * Copyright 2008 the original author or authors.
// * 
// * UPDATE: the code was extracted from its original project and
// * slightly modified to help with our project.
// * 
// * Licensed under the Apache License, Version 2.0 (the "License");
// * you may not use this file except in compliance with the License.
// * You may obtain a copy of the License at
// * 
// *       http://www.apache.org/licenses/LICENSE-2.0
// * 
// * Unless required by applicable law or agreed to in writing, software
// * distributed under the License is distributed on an "AS IS" BASIS,
// * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// * See the License for the specific language governing permissions and
// * limitations under the License.
// */
//package algos;
//
//import junit.framework.TestCase;
//
//import org.junit.Before;
//import org.junit.Test;
//import org.junit.runner.JUnitCore;
//
///** 
// * @author Peter Karich, peat_hal 'at' users 'dot' sourceforge 'dot' net
// * @author Ahmed Abdelkader
// */
//public class AssignmentAlgorithmTester extends TestCase {
//
//    protected HungarianAlgorithm algorithm;
//    protected final float F_MAX = Float.MAX_VALUE;
//    
//    @Before
//    @Override
//    public void setUp() {
//        algorithm = new HungarianAlgorithm();
//    }
//
//    protected HungarianAlgorithm createAlgorithm() {
//    	return new HungarianAlgorithm();
//    }
//
//    /**
//     * Test der Methode calculate, in Klasse de.gstpl.algo.assignment.AssignmentAlgorithm.
//     */
//    @Test
//    public void testCalculate() {
//        System.out.println("testCalculate");
//
//        // We look for the minimal weighted bipartite graph.
//        // This is equivalent to the following problem:
//        //  calculate the minimal sum over all "main-diagonal-elements"
//        //  only via row or column reordering
//
//        // WARNING: we can't process negative weights, because of the definition!
//        //          so all elements of the matrix should be nonnegative!
//
//        float matrix[][] = {
//            {14, 5, 8, 7},
//            {2, 12, 6, 5},
//            {7, 8, 3, 9},
//            {2, 4, 6, 10}
//        };
//
//        //{row of col0, column0}, {row of col1, column1}, ...
//        int expResult[][] = {
//            {3, 0},
//            {0, 1},
//            {2, 2},
//            {1, 3}
//        };
//
//        //System.out.println(new VisibleArray(matrix));
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 4 : result.length;
//
//        //System.out.println(new VisibleArray(matrix));
//        //System.out.println(new VisibleArray(result));
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    @Test
//    public void testCalculatePaper() {
//        float matrix[][] = {
//            {4,    6, F_MAX, 10},
//            {5,    7,     8, 11},
//            {4,    6,     7, 10},
//            {F_MAX,3,     4,  7}
//        };
//
//        //{row of col0, column0}, {row of col1, column1}, ...
//        int expResult[][] = {
//            {1, 0},
//            {0, 1},
//            {2, 2},
//            {3, 3}
//        };
//
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 4 : result.length;
//
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertTrue(expSum > 0);
//        System.out.println("SUM:" + resSum + " expSum:" + expSum);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    public float[][] cloneMatrix(float[][] matrix) {
//        float[][] cMatrix = new float[matrix.length][];
//
//        for (int i = 0; i < matrix.length; i++) {
//            cMatrix[i] = (float[]) matrix[i].clone();
//        }
//        return cMatrix;
//    }
//
//    @Test
//    public void testCalculate2() {
//        System.out.println("testCalculate2");
//        float matrix[][] = new float[][]{
//            {4, 6, 1, 2},
//            {5, 6, 7, 6},
//            {7, 4, 5, 8},
//            {4, 4, 6, 8}
//        };
//        int expResult[][] = new int[][]{{3, 0}, {2, 1}, {0, 2}, {1, 3}};
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 4 : result.length;
//
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertTrue(expSum > 0);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    @Test
//    public void slightlyChangedTestCalculate2() {
//        System.out.println("slightlyChangedTest2");
//        float matrix[][] = new float[][]{
//            {4, 6, 1, 2},
//            {5, 6, 7, 6},
//            {7, 4, 5, 5},
//            {4, 4, 6, 5}
//        };
//        int expResult[][] = new int[][]{{1, 0}, {2, 1}, {0, 2}, {3, 3}};
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 4 : result.length;
//
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    @Test
//    public void testMoreRowsThanColumns() {
//        System.out.println("testMoreRowsThanColumns");
//        float matrix[][] = new float[][]{
//            {4, 6, 1},
//            {5, 6, 7},
//            {7, 4, 5},
//            {4, 4, 6}
//        };
//        int expResult[][] = new int[][]{{3, 0}, {2, 1}, {0, 2}, null};
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 4 || result.length == 3 : result.length;
//
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    @Test
//    public void testIfAlgoCanSolveTrivialProblems() {
//        System.out.println("testIfAlgoMakesDecisionsFast");
//        float matrix[][] = new float[][]{{0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}};
//        int expResult[][] = new int[][]{{0, 0}, {1, 1}, {2, 2}, {3, 3}};
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 4 : result.length;
//
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    @Test
//    public void testJohnClarkExample() {
//        System.out.println("testJohnClarkExample");
//        //the sample in john clark's book
//        float matrix[][] = new float[][]{
//            {3, 5, 5, 4, 1, 2, 3},
//            {5, 7, 7, 6, 5, 4, 6},
//            {2, 0, 2, 2, 2, 2, 1},
//            {2, 4, 4, 4, 3, 2, 4},
//            {1, 2, 1, 3, 1, 3, 1},
//            {6, 8, 8, 5, 8, 7, 8},
//            {2, 4, 4, 1, 0, 3, 3}
//        };
//
////        int result1[][] = new int[][]{
////            {2, 0}, {6, 1}, {1, 2}, {0, 3},
////            {5, 4}, {4, 5}, {3, 6}
////        }; //Sum is maximal: 32f
////
////        int result2[][] = new int[][]{
////            {2, 0}, {1, 1}, {0, 2}, {3, 3},
////            {5, 4}, {4, 5}, {6, 6}
////        }; //Sum is 32f
//
//        int expResult[][] = new int[][]{
//            {2, 0}, {6, 1}, {0, 2}, {1, 3},
//            {5, 4}, {4, 5}, {3, 6}
//        }; //Sum is 32f
//
//        // our algorithm looks for the minimal not maximal weighted (bipartite)
//        // graph so 'invert' the entries to get the same assignment as in the book
//        float VALUE = 10;
//        for (int y = 0; y < matrix.length; y++) {
//            for (int x = 0; x < matrix[0].length; x++) {
//                matrix[y][x] = VALUE - matrix[y][x];
//            }
//        }
//
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 7 : result.length;
//
//        //checkResult(instance.computeAssignments(matrix), expResult);
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    @Test
//    public void testBondyMurtyExample() {
//        System.out.println("testJohnClarkExample");
//        //the sample in john clark's book
//        float matrix[][] = new float[][]{
//            {3, 5, 5, 4, 1},
//            {2, 2, 0, 2, 2},
//            {2, 4, 4, 1, 0},
//            {0, 1, 1, 0, 0},
//            {1, 2, 1, 3, 3}
//        };
//
//        int expResult[][] = new int[][]{
//            {3, 0}, {0, 1}, {2, 2}, {1, 3},
//            {4, 4}
//        };
//        //Sum is 14f
//        float VALUE = 10;
//        for (int y = 0; y < matrix.length; y++) {
//            for (int x = 0; x < matrix[0].length; x++) {
//                matrix[y][x] = VALUE - matrix[y][x];
//            }
//        }
//
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 5 : result.length;
//
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    @Test
//    public void testSmallWithInfinity() {
//        System.out.println("testSmallWithInfinity");
//        float matrix[][] = new float[][]{
//            {15.0f, 11.0f, 0},
//            {12.0f, F_MAX, 4},
//            {3.00f, F_MAX, 4}
//        };
//        int expResult[][] = new int[][]{{2, 0}, {0, 1}, {1, 2}};
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 3 : result.length;
//
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    @Test
//    public void testMoreColumnsThanRows() {
//        System.out.println("testMoreColumnsThanRows");
//        //Check if algo works for more ti's (columns) than rows        
//        float matrix[][] = new float[][]{
//            {15, 11.0f, 0},
//            {12, F_MAX, 4}
//        };
//        int expResult[][] = new int[][]{{1, 0}, null, {0, 2}};
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 3 : result.length;
//
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    @Test
//    public void testOptimizeLocation() {
//        // Check if algo optimizes the room for the last event (column), 
//        // if there are more room's (rows) than events (cols)
//        float matrix[][] = new float[][]{
//            {15.0f, 11.0f},
//            {12.0f, F_MAX},
//            {3.00f, F_MAX}
//        };
//        int expResult[][] = new int[][]{{2, 0}, {0, 1}};
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 3 || result.length == 2 : result.length;
//
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//
//    @Test
//    public void testComplicateMatrix() {
//        float matrix[][] = new float[][]{
//            {F_MAX, 11.0f, F_MAX, F_MAX, F_MAX, F_MAX, 16.0f, 31.0f, 21.0f, F_MAX},
//            {F_MAX, F_MAX, F_MAX, 12.0f, F_MAX, F_MAX, 14.0f, F_MAX, 19.0f, F_MAX},
//            {F_MAX, F_MAX, F_MAX, F_MAX, F_MAX, F_MAX, 4.00f, F_MAX, 9.00f, F_MAX},
//            {F_MAX, F_MAX, F_MAX, F_MAX, F_MAX, F_MAX, F_MAX, 6.00f, F_MAX, 19.0f},
//            {19.0f, F_MAX, F_MAX, F_MAX, F_MAX, F_MAX, 16.0f, F_MAX, 21.0f, F_MAX},
//            {F_MAX, F_MAX, 33.0f, F_MAX, F_MAX, 23.0f, 8.00f, F_MAX, 13.0f, F_MAX},
//            {F_MAX, F_MAX, F_MAX, F_MAX, F_MAX, F_MAX, 14.0f, F_MAX, 19.0f, F_MAX},
//            {F_MAX, F_MAX, 38.0f, F_MAX, F_MAX, 28.0f, 13.0f, F_MAX, 18.0f, F_MAX},
//            {F_MAX, F_MAX, 37.0f, F_MAX, 19.0f, 27.0f, 12.0f, F_MAX, 17.0f, F_MAX},
//            {F_MAX, F_MAX, 36.0f, F_MAX, F_MAX, 26.0f, 11.0f, 26.0f, 16.0f, F_MAX}
//        };
//        int expResult[][] = new int[][]{{4, 0}, {0, 1}, {5, 2}, {1, 3}, {8, 4},
//            {7, 5}, {2, 6}, {9, 7}, {6, 8}, {3, 9}
//        };
//        int result[][] = algorithm.computeAssignments(cloneMatrix(matrix));
//        assert result.length == 10 : result.length;
//
//        float resSum = AssignmentHelper.calculateSum(matrix, result);
//        float expSum = AssignmentHelper.calculateSum(matrix, expResult);
//        assertEquals(expSum, resSum, 0.001f);
//    }
//    
//    public static void main(String[] args) {
//		JUnitCore.runClasses(AssignmentAlgorithmTester.class);
//	}
//}
